
package com.amado.sprintboot.redscache;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.amado.sprintboot.redscache.entity.User;
import com.amado.sprintboot.redscache.service.UserService;

@SpringBootApplication
@Controller
@EnableCaching
public class SpringbootRedisCacheApplication {

    @Autowired
    @Qualifier("UserServiceSpringCacheRedisImpl")
    private UserService userService;

    @GetMapping("/get/{id}")
    @ResponseBody
    public User get(@PathVariable String id) {
        return userService.getUser(id);
    }

    @GetMapping("/delete/{id}")
    @ResponseBody
    public String delete(@PathVariable String id) {
        userService.deleteUser(id);
        return "success";
    }

    @GetMapping("/update/{id}")
    @ResponseBody
    public String update(@PathVariable String id) {
        User user = new User();
        user.setUserId(id);
        user.setName("aa");
        userService.upateUser(user);
        return "success";
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringbootRedisCacheApplication.class, args);
    }
}
